import request from '@/utils/request.js'

const state = {
	headerNavList: [],
	swiperList: [],
	navList: [],
	bannerList: {},
	advList: {},
	addressList: [],
	showItemList: []
}

const mutations = {
	SET_HEADERNAVLIST(state, headerNavList) {
		state.headerNavList = headerNavList
	},
	SET_SWIPERLIST(state, swiperList) {
		state.swiperList = swiperList
	},
	SET_NAVLIST(state, navList) {
		state.navList = navList
	},
	SET_BANNERLIST(state, bannerList) {
		state.bannerList = bannerList
	},
	SET_ADVLIST(state, advList) {
		state.advList = advList
	},
	SET_ADDRESSLIST(state, addressList) {
		state.addressList = addressList
	},
	SET_SHOWITEMLIST(state, showItemList) {
		state.showItemList = showItemList
	}
}

const actions = {
	async getHeaderNavList({commit}) {
		try{
			const result = await request('/getHeaderNavList')
			commit('SET_HEADERNAVLIST', result)
		}catch(e){
			console.log('请求获取头部导航失败')
		}
	},
	
	async getSwiperList({commit}) {
		try{
			const result = await request('/getIndexSwiperList')
			commit('SET_SWIPERLIST', result)
		}catch(e){
			//TODO handle the exception
			console.log('请求获取轮播图失败')
		}
	},
	
	async getNavList({commit}) {
		try{
			const result = await request('/getIndexNavList')
			commit('SET_NAVLIST', result)
		}catch(e){
			//TODO handle the exception
			console.log('请求获取导航失败')
		}
	},
	
	async getBannerList({commit}) {
		try{
			const result = await request('/getIndexBannerList')
			commit('SET_BANNERLIST', result)
		}catch(e){
			//TODO handle the exception
			console.log('请求获取banner失败')
		}
	},
	
	async getAdvList({commit}) {
		try{
			const result = await request('/getIndexAdv')
			commit('SET_ADVLIST', result)
		}catch(e){
			//TODO handle the exception
			console.log('请求获取banner失败')
		}
	},
	
	async getAddressList({commit}) {
		try{
			const result = await request('/getIndexAddressList')
			commit('SET_ADDRESSLIST', result)
		}catch(e){
			//TODO handle the exception
			console.log('请求获取adv失败')
		}
	},
	
	async getShowItemList({commit}) {
		try{
			const result = await request('/getIndexShowItem')
			commit('SET_SHOWITEMLIST', result)
		}catch(e){
			//TODO handle the exception
			console.log('请求获取最下方列表失败')
		}
	},
	
}

const getters = {
	
}

export default {
	namespaced: true,
	state,
	mutations,
	actions,
	getters
}